package com.iciot.utils;

import java.sql.*;

public class JDBCUtils {
    private static String url = "jdbc:mysql://localhost:3306/studentm?useSSL=false";
    private static String username = "root";
    private static String password = "123456";

    static {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    public static Connection getCon() throws SQLException {
        Connection con = DriverManager.getConnection(url, username, password);
        return con;
    }

    public static void close(Connection con, PreparedStatement ps, ResultSet rs) throws SQLException {
        if (con != null) {
            con.close();
            con = null;
        }
        if (ps != null) {
            ps.close();
            ps = null;
        }
        if (rs != null) {
            rs.close();
            rs = null;
        }
    }

}
